<?php

namespace app\master\controller;

use think\captcha\Captcha;
use think\Controller;

class PublicController extends Controller
{

    /**
     * 检测图形验证码
     * @param $code
     * @return bool
     */
    public function checkCaptcha($code)
    {
        $captcha = new Captcha();
        return $captcha->check($code);
    }

    /**
     * layui table 表格返回方法
     * @param int $code
     * @param string $msg
     * @param int $count
     * @param array $data
     */
    public function tableReturn($code = 0, $msg = "", $count = 0, $data = [])
    {
        $data = ['code' => $code, 'msg' => $msg, 'count' => $count, 'data' => $data];
        exit(json_encode($data));
    }

    /**
     * ajax 返回方法
     * @param int $code
     * @param string $msg
     * @param string $url
     * @param array $data
     */
    public function ajaxReturn($code = 0, $msg = "", $url = '', $data = [])
    {
        $data = array(
            "code" => $code,
            "msg" => $msg,
            'jumpUrl' => $url,
            "data" => $data
        );

        header('Content-Type:application/json; charset=utf-8');
        exit(json_encode($data, JSON_FORCE_OBJECT));
    }
}